package com.cxx.purchasecharge.component.controller;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cxx.purchasecharge.component.bean.ActionResult;
import com.cxx.purchasecharge.component.bean.BaseBean;
import com.cxx.purchasecharge.component.bean.DataGridRequestForm;
import com.cxx.purchasecharge.component.utils.AjaxUtils;

@Controller
public abstract class GenericController
{
    @SuppressWarnings ("unused")
    private static final Logger logger = Logger.getLogger (GenericController.class);

    private String viewName;

    @RequestMapping (value = "/")
    public String initView (ModelMap model)
    {
        return viewName;
    }

    @RequestMapping (value = "/checkExist", method = RequestMethod.POST)
    public @ResponseBody
    String checkExist (@RequestParam String id, @RequestParam String value)
    {
        if (StringUtils.isBlank (id))
        {
            // new
        }
        else
        {
            // edit
        }

        return "true";
    }

    @RequestMapping (value = "/getAllModel", method = RequestMethod.POST)
    public @ResponseBody
    String getAllModel (DataGridRequestForm dataGridRequestForm)
    {
        return "";
    }

    @RequestMapping (value = "/addModel", method = RequestMethod.POST)
    public @ResponseBody
    String addModel (BaseBean bean, BindingResult result)
    {
        return AjaxUtils.getJsonObject (ActionResult.createActionResult ().build ());
    }

    @RequestMapping (value = "/updateModel", method = RequestMethod.POST)
    public @ResponseBody
    String updateModel (BaseBean bean, BindingResult result)
    {
        return AjaxUtils.getJsonObject (ActionResult.createActionResult ().build ());
    }

    @RequestMapping (value = "/deleteModel", method = RequestMethod.POST)
    public @ResponseBody
    String deleteModel (@RequestParam String id)
    {
        return AjaxUtils.getJsonObject (ActionResult.createActionResult ().build ());
    }

    @RequestMapping (value = "/deleteModels", method = RequestMethod.POST)
    public @ResponseBody
    String deleteModels (@RequestParam String ids)
    {
        return AjaxUtils.getJsonObject (ActionResult.createActionResult ().build ());
    }
}
